package day0521;

import java.util.Arrays;

public class Test7 {
    public static void main(String[] args) {
        int[] a={41, 8 ,4};
        int[] b2=copyOf(a , 2);
        System.out.println(Arrays.toString(b2));
    }

    private static int[] copyOf(int[] a,int count) {
        //b={41, 8 ,4, 0,0}
        int[] b=new int[count];
        if(count>a.length){
            count=a.length;
        }
        for (int i = 0; i < count; i++) {
            //将a数组的第i个元素存入到b数组的第i个位置
            b[i]=a[i];
        }
        a=b;
        return b;
    }
}
